package com.hongye.house.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hongye.house.entity.CityHomeEntity;
import com.hongye.house.service.CityHomeService;
import com.hongye.common.utils.PageUtils;
import com.hongye.common.utils.R;

import javax.servlet.http.HttpSession;


/**
 * 城市表；省市区
 *
 * @author lins
 * @email 695565697@qq.com
 * @date 2021-10-14 13:32:23
 */
@RestController
@RequestMapping("house/cityhome")
public class CityHomeController {
    @Autowired
    private CityHomeService cityHomeService;


    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = cityHomeService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 省市县递归三级联动
     */
    @RequestMapping("/selchild")
    public R selchild(){
        List<CityHomeEntity> list=cityHomeService.selchild();

        return R.ok().put("selchild",list);
    }




    /**
     * 信息
     */
    @RequestMapping("/info/{pid}")
    public R info(@PathVariable("pid") Integer pid){
		CityHomeEntity cityHome = cityHomeService.getById(pid);

        return R.ok().put("cityHome", cityHome);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody CityHomeEntity cityHome){
		cityHomeService.save(cityHome);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody CityHomeEntity cityHome){
		cityHomeService.updateById(cityHome);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] pids){
		cityHomeService.removeByIds(Arrays.asList(pids));

        return R.ok();
    }

}
